package com.sample.qr;

import android.os.Handler;
import android.os.Looper;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.Toast;

public abstract class BaseActivity extends AppCompatActivity {
    private Toast toast;

    public void showToast(CharSequence sequence) {
        if (toast == null)
            toast = Toast.makeText(this, sequence, Toast.LENGTH_SHORT);
        else {
            toast.setText(sequence);
            toast.setDuration(Toast.LENGTH_SHORT);
        }
        Handler handlerThree = new Handler(Looper.getMainLooper());
        handlerThree.post(() -> toast.show());
    }

    public void cancel() {
        Handler handlerThree = new Handler(Looper.getMainLooper());
        handlerThree.post(() -> {
            if (null != toast)
                toast.cancel();
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        cancel();
    }
}
